package com.ruoyi.partybuilding.common;


import lombok.var;
import org.springframework.stereotype.Service;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;

@Service("pb")
public class PbPower {

    //上级1，类型c，名称，权限,路径
    public final static   String _perfix = "partybuilding";
    public final  static   files files=new files();
    public final static   workScore workScore= new workScore();
    public final static  meetingInfo meetingInfo=new meetingInfo();
    public final static releaseTask releaseTask=new releaseTask();

    public static List<String> gainList(List<String> list) {
        if (list == null)
            list = new ArrayList<>();
        var classz = PbPower.class;
        Field[] fields = classz.getDeclaredFields();
        for (Field field : fields) {
            if (!Modifier.isPublic(field.getModifiers()))
                continue;
            try {
                if (field.getType() == String.class || field.getType().isPrimitive()) {
                    if (Modifier.isStatic(field.getModifiers()))
                        list.add(field.get(null) + "");
                } else if (PowerCommSet.class.isAssignableFrom(field.getType()))
                    ((PowerCommSet) field.get(null)).gainList(list);
            } catch (IllegalAccessException e) {
                System.out.println("反射获取异常");
            }
        }
        return list;
    }

    public static class workScore extends PowerCommSet{
        public final   String _perfix=PbPower._perfix+":WorkScore";
        public final   String approveOrg=_perfix+":approveOrg";
        public final    String approve=_perfix+":approve";
        public final String applyForAdding=_perfix+ ":applyForAdding";
        public final String applyForAddingOrg=_perfix+ ":applyForAddingOrg";
        public final String queryOrg=_perfix+":queryOrg";
        public final String exportOrg=_perfix+":exportOrg";
        public final String export=_perfix+":export";

    }

    public static class meetingInfo extends PowerCommSet{
        public final String _perfix = PbPower._perfix + ":MeetingInfo";
        public final String signManage = _perfix + ":signManage";
    }
    public static class review extends PowerCommSet{
        public final String _perfix = PbPower._perfix + ":review";
        public final String queryMy = _perfix + ":queryMy";
        public final String orgReview = _perfix + ":orgReview";

        public final String result = _perfix + ":result";

    }
    public static  class releaseTask extends PowerCommSet {

        //public final String _perfix = PbPower._perfix + ":releaseTask";
        public String myList;
        public String list;
        public String query;
        public String edit;
        public String remove ;
        public String applyFor ;
        public String submit ;
        public String publish;
        public String approval;
        public String acceptTask ;
        public String records;
        public String addRecord ;
        public String done ;
        public String review ;
        public String reward ;
        public String usage ;



    }
    public static class files extends PowerCommSet{
        public final   String _perfix=PbPower._perfix+":Files";
        public final    String expret=_perfix+":export";
    }
    public static abstract class PowerCommSet{
        public    PowerCommSet() {

            PowerStrSet();
        }
        public  void PowerStrSet() {
            Field[] fields = this.getClass().getDeclaredFields();
            for (Field field : fields) {
                /**
                 if (Modifier.isFinal(field.getModifiers())) {
                 field.setAccessible(true);
                 try {
                 field.set(this, fmtValByName(field.getName()));
                 } catch (IllegalAccessException e) {
                 System.out.println("属性设置异常");
                 e.printStackTrace(System.out);
                 }
                 }else
                 */
                if (!Modifier.isFinal(field.getModifiers()) && Modifier.isPublic(field.getModifiers()) && field.getType() == String.class && !Modifier.isStatic(field.getModifiers())) {
                    try {
                        field.set(this, fmtValByName(field.getName()));
                    } catch (IllegalAccessException e) {
                        System.out.println("属性设置异常");
                        e.printStackTrace(System.out);
                    }
                }
            }
        }
        public List<String> gainList(List<String> list) {
            if (list == null)
                list = new ArrayList<>();
            var obj = this;
            Field[] fields = this.getClass().getDeclaredFields();
            for (Field field : fields) {
                if (!Modifier.isPublic(field.getModifiers()))
                    continue;
                try {

                    if (field.getType() == String.class || field.getType().isPrimitive()) {
                        list.add(field.get(obj) + "");
                    } else if (PowerCommSet.class.isAssignableFrom(field.getType()))
                        ((PowerCommSet) field.get(obj)).gainList(list);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException(e);
                }
            }
            return list;
        }
        public String fmtValByName(String fieldName){
            return PbPower._perfix+":" + this.getClass().getSimpleName()+":"+fieldName;
        }
    }

}
